package cn.edu.sgu.www.mhxysy.controller.fabao;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.fabao.FabaoSixiangAttributeCategoryDTO;
import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoSixiangAttributeCategory;
import cn.edu.sgu.www.mhxysy.pager.fabao.FabaoSixiangAttributeCategoryPager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.fabao.FabaoSixiangAttributeCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "法宝四象管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/fabao_sixiang_attribute_category", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class FabaoSixiangAttributeCategoryController {

	private final FabaoSixiangAttributeCategoryService fabaoSixiangAttributeCategoryService;

	@Autowired
	public FabaoSixiangAttributeCategoryController(FabaoSixiangAttributeCategoryService fabaoSixiangAttributeCategoryService) {
		this.fabaoSixiangAttributeCategoryService = fabaoSixiangAttributeCategoryService;
	}

	@ApiOperation("添加法宝四象")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated FabaoSixiangAttributeCategoryDTO fabaoSixiangAttributeCategoryDTO) {
		fabaoSixiangAttributeCategoryService.insert(fabaoSixiangAttributeCategoryDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID修改法宝四象信息")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated FabaoSixiangAttributeCategoryDTO fabaoSixiangAttributeCategoryDTO) {
		fabaoSixiangAttributeCategoryService.updateById(fabaoSixiangAttributeCategoryDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("分页查询法宝四象列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<FabaoSixiangAttributeCategory>> selectByPage(FabaoSixiangAttributeCategoryPager pager) {
		Page<FabaoSixiangAttributeCategory> page = fabaoSixiangAttributeCategoryService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}